package net.lanelife.casino.caipiao.dto.admin;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;

import net.lanelife.casino.caipiao.entity.QuotaRecord;
import net.lanelife.casino.caipiao.entity.QuotaRecord_;
import net.lanelife.casino.common.dto.support.GenericTable;

import com.google.common.collect.Lists;

public class QuotaRecordTable<DTO> extends GenericTable<DTO, QuotaRecord> {

	private static final long serialVersionUID = 3228095158124416442L;
	
	private Long inQuota;
	
	private Long outQuota;

	public QuotaRecordTable() {}
	
	public QuotaRecordTable(Long inQuota, Long outQuota) {
		super();
		this.inQuota = inQuota;
		this.outQuota = outQuota;
	}
	
	@Override
	public List<Selection<?>> buildExpression(Root<QuotaRecord> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
		List<Selection<?>> columns = Lists.newArrayList();
		columns.add(builder.sum(builder.<Long>selectCase().when(builder.equal(root.get(QuotaRecord_.direction), QuotaRecord.Direction.IN), root.<Long>get(QuotaRecord_.quota)).otherwise(0L)));
		columns.add(builder.sum(builder.<Long>selectCase().when(builder.equal(root.get(QuotaRecord_.direction), QuotaRecord.Direction.OUT), root.<Long>get(QuotaRecord_.quota)).otherwise(0L)));
		return columns;
	}

	public Long getInQuota() {
		return inQuota;
	}

	public void setInQuota(Long inQuota) {
		this.inQuota = inQuota;
	}

	public Long getOutQuota() {
		return outQuota;
	}

	public void setOutQuota(Long outQuota) {
		this.outQuota = outQuota;
	}

	
}
